﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using UCNKompetenceBors.Model;
using UCNKompetenceBors.Database;

namespace UCNKompetenceBors.User
{
    public partial class profile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            

            if (!Page.IsPostBack)
            {
                BindSubMenu();
                BindData();

                #region Globalization
                string culture = String.Empty;

                if (HttpContext.Current.Session["MyCulture"] != null)
                    culture = HttpContext.Current.Session["MyCulture"].ToString();

                if (!String.IsNullOrEmpty(culture))
                    GeneralTools.SetCulture(culture);

                LocalizeControls();
                #endregion
            }
        }

        /// <summary>
        /// Binds the sub menu links.
        /// </summary>
        private void BindSubMenu()
        {
            hyLinkProfile.NavigateUrl = "~/User/profile.aspx?uid=" + Request.QueryString["uid"];
            hyLinkEditProfile.NavigateUrl = "~/User/editProfile.aspx?uid=" + Request.QueryString["uid"];
            hyLinkChangePassword.NavigateUrl = "~/User/changePassword.aspx?uid=" + Request.QueryString["uid"];
            hyLinkSettings.NavigateUrl = "~/User/editSettings.aspx?uid=" + Request.QueryString["uid"];
            hyLinkSale.NavigateUrl = "~/User/userSale.aspx?uid=" + Request.QueryString["uid"];
            hyLinkPurchases.NavigateUrl = "~/User/userPurchase.aspx?uid=" + Request.QueryString["uid"];
        }

        /// <summary>
        /// Binds the data of the profile based on the "uid" QueryString.
        /// </summary>
        private void BindData()
        {
            LoginUser user = dbProfile.GetProfileDetails(Guid.Parse(Request.QueryString["uid"]));

            if (user != null)
            {
                lblUserName.Text = user.UserName;
                lblCreateDate.Text = user.CreatedDate.ToString("dd-MM-yyyy");
                lblName.Text = user.FirstName + " " + user.LastName;
                lblMail.Text = user.Email;
                lblPhone.Text = user.Phone;
                lblBio.Text = user.Biography;
            }
        }

        /// <summary>
        /// Localizes the controls of the site, based on the current UI Culture.
        /// </summary>
        private void LocalizeControls()
        {
            hyLinkChangePassword.Text = GetLocalResourceObject("hyLinkChangePasswordText").ToString();
            hyLinkEditProfile.Text = GetLocalResourceObject("hyLinkEditProfileText").ToString();
            hyLinkProfile.Text = GetLocalResourceObject("hyLinkProfileText").ToString();
            hyLinkPurchases.Text = GetLocalResourceObject("hyLinkPurchasesText").ToString();
            hyLinkSale.Text = GetLocalResourceObject("hyLinkSaleText").ToString();
            hyLinkSettings.Text = GetLocalResourceObject("hyLinkSettingsText").ToString();

            lblBioHeader.Text = GetLocalResourceObject("lblBioHeaderText").ToString();
            lblMailHeader.Text = GetLocalResourceObject("lblMailHeaderText").ToString();
            lblNameHeader.Text = GetLocalResourceObject("lblNameHeaderText").ToString();
            lblPhoneHeader.Text = GetLocalResourceObject("lblPhoneHeaderText").ToString();
        }
    }
}